      SUBROUTINE WRIGRD(z,xmin,xmax,ymin,ymax,zmin,zmax &
      &  ,m0,m1,n0,n1,i0,i1,j0,j1,fname)


      implicit real*8(a-h,o-z)
      character*80 fname
      dimension z(m0:m1,n0:n1)


!c     write(*,'(a40,8i4,4f10.0)') fname,i0,i1,j0,j1
!c    :  ,m0,m1,n0,n1,xmin,xmax,ymin,ymax
      zmin=z(i0,j0)
      zmax=z(i0,j0)


      do j=j0,j1
         do i=i0,i1
           zmin=min(zmin,z(i,j))
           zmax=max(zmax,z(i,j))
         enddo
      enddo


      open(77,file=fname,status='unknown')
      write(77,'(a4)') 'DSAA'
      write(77,'(2i5)') (i1-i0+1),(j1-j0+1)
      write(77,'(2e15.7)') xmin,xmax
      write(77,'(2e15.7)') ymin,ymax
      write(77,'(2e15.7)') zmin,zmax


      do j=j0,j1
         write(77,'(5E15.7)') (z(i,j),i=i0,i1)
      enddo


      close(77)
      return
      END
